<?php
/**
 * Created by PhpStorm.
 * User: Shen
 * Date: 2016/7/21
 * Time: 21:24
 * 数据对象映射模式，是将对象和数据存储映射起来，对一个对象的操作会映射为对数据存储的操作，
 * 比如ORM类，将复杂的SQL语句映射成对象属性的操作。
 */

namespace DuiCode;


class User{
    public  $id;
    public  $name;
    public  $mobile;
    public  $regtime;

    protected  $db;

    function  __construct($id){
            $this->db = new \DuiCode\Database\MySQLi();
            $this->db->connect('127.0.01','root','root','test');
            $res = $this->db->query("SELECT * FROM user LIMIT 1;");
            $data = $res->fetch_assoc();

            $this->id = $data['id'];
            $this->name=$data['name'];
            $this->mobile=$data['mobile'];
            $this->regtime=$data['regtime'];
    }

    function  __destruct(){
        // TODO: Implement __destruct() method.
            $this->db->query("UPDATE user SET name = '{$this->name}',mobile='{$this->mobile}',regtime='{$this->regtime}' WHERE id = {$this->id} LIMIT 1;");
    }
}